# Definition for a binary tree node.
# class TreeNode(object):
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution(object):
    def __init__(self):
        self.inlist = []
        self.min = float('inf')

    def getMinimumDifference(self, root):
        """
        :type root: Optional[TreeNode]
        :rtype: int
        """
        self.loop(root)
        return self.min

    def loop(self, node):
        if not node:
            return
        self.loop(node.left)
        self.inlist.append(node.val)
        if len(self.inlist) > 1:
            if self.inlist[-1] - self.inlist[-2] < self.min:
                self.min = self.inlist[-1] - self.inlist[-2]
        self.loop(node.right)


